<?php

class topic_request extends CI_Controller {

    function __Construct() {
        parent::__Construct();
        $this->load->database();
        $this->load->model('topic_request_m');
        $this->load->library('form_validation');
        $this->load->library("pagination");
        $this->load->helper('url', 'form');
    }

    function index() {

        $this->data['all_topic_request'] = $this->topic_request_m->get();
        $this->example1();
        //$this->load->view('admin/topic_request/index',$this->data);
    }

    public function topic_request() {
        $this->data['all_topic_request'] = $this->topic_request_m->get();
        $this->example1();
    }

    public function edit($id = NULL) {
        if ($id) {
            $this->data['topic_request'] = $this->topic_request_m->get($id);
            count($this->data['topic_request']) || $this->data['errors'] = 'topic_request could not be found';
        } else {
            $this->data['topic_request'] = $this->topic_request_m->get_new_topic_request();
        }

        //set up rule
        $rules = $this->topic_request_m->rules_topic_request;
        $this->form_validation->set_rules($rules);
        if ($this->form_validation->run() == TRUE) {

            $data = $this->topic_request_m->array_from_post(
                    array('topic_request_title', 'topic_request_content', 'topic_request_dated', 'topic_request_author', 'topic_request_status')
            );
            $data['topic_request_author'] = 50;
            $this->topic_request_m->save($data, $id);
            redirect('admin/topic_request');
        }
        $this->load->view('admin/topic_request/topic_request_edit', $this->data);
    }

    public function delete($id) {
        $this->topic_request_m->delete($id);
        redirect('admin/topic_request');
    }

    public function example1() {
        $config = array();
        $config["base_url"] = site_url('admin/topic_request/topic_request/');
        $config["total_rows"] = $this->topic_request_m->record_count();
        $config["per_page"] = 4;
        $config["uri_segment"] = 4;



        $this->pagination->initialize($config);

        $page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;

        $this->data["results"] = $this->topic_request_m->fetch_picr($config["per_page"], $page);
        $this->data["links"] = $this->pagination->create_links();
        $this->load->view('admin/topic_request/index', $this->data);
    }

}

?>